<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色授权后台</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/assets/layui-v2.5.5/css/layui.css" media="all" />
</head>
<body>
<div class="layui-fluid" style="margin-top:2%;">
<form class="layui-form" action="">
<div id="test1"></div>
<br/>
<br/>
<div class="layui-form-item">
	<div class="layui-input-block" style="text-align: center;margin:0 auto;">
		<button class="layui-btn" lay-submit="" lay-filter="submit-role">保存</button> 
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</div>
</form>
</div>
<script src="/assets/layui-v2.5.5/layui.js" charset="utf-8"></script> 
<script>
var $,form,tree,mydata;
	var roleId='#(id)';
	layui.use(['form','jquery','tree'], function(){
	  form = layui.form;
	  tree = layui.tree;
	  $ = layui.$;
	  mydata=#(menus);
	//渲染
	    var inst1 = tree.render({
	      elem: '#test1'  //绑定元素
	      ,showCheckbox:true
	      ,data: mydata
	      ,id: 'demoId' //定义索引
	    });
	    //重置按钮重置checkbox
        $(".layui-btn-primary").click(function(){
        	tree.setChecked('demoId', []); // 	
        });
	  //提交表单
		form.on('submit(submit-role)', function(obj){
			//获得选中的节点
			var checkData = tree.getChecked('demoId');
			savePowerWeb(checkData);
			return false;
			});
	});
	function savePowerWeb(checkData){
	 	$.ajax({
		    url : '/role/savePowerWeb',
			type : "post",
			data : {checkData:JSON.stringify(checkData),roleId:roleId},
			dataType : "json",
			success : function(ret) {
				if (ret.state == 'ok') {
					layer.msg(ret.msg, {icon: 1, offset: '15px', time: 600}, function(){
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.$(".layui-laypage-btn").click();
					});
				} else {
					layer.msg(ret.msg, {icon: 2, offset: '10px'});
				}
			},
			error: function() {
	      } 
	  }); 
	}
</script> 
</body>
</html>